﻿var page = {
    wifiPanel_isShown: false,

    /* 此方法在第一次显示窗体前发生 */
    onLoad: function (event) {
        this.wifiPanel_isShown = true;
        refreshDate(this);          //获取信号质量--app.js                
        main_Setting_page = this;   //设置该Page的值 ----app.js----
        wifi.module.scan();         //扫描wifi信道 =====> 成功在app.js中回调
    },

    //点击某一个网络---联网时触发单击事件
    onWifiConnect: function (event) {
        if (typeof (this.wifiApArray) == "object") {
            console.log("@@wifiApArray=======" + typeof (this.wifiApArray));
            if (wifi.connect_timer != 0) {
                clearInterval(wifi.connect_timer);
                wifi.connect_timer = 0;
            }
            var index = parseInt(event.target.id.substring(11));
            audio.stop();
            pm.navigateTo({ url: "wifiConnectPage/wifiConnectPage", value: this.wifiApArray[index] })
        }
    },

    //相关 page 关闭返回到当前 page 回调函数，并返回相关 page 中的参数
    onUpdate: function (event) {
        console.log("===================================================onUpdate=====================================================" + event);
        var that = this;

        //输入密码后---进行wifi联网
        if (event.value.page == "wifiConnectPage") {
            if (wifi.connect_timer != 0) {
                clearInterval(wifi.connect_timer);
                wifi.connect_timer = 0;
            }
            wifi.current_ap = new Object();
            wifi.current_ap.ssid = event.value.ssid;
            wifi.current_ap.bssid = event.value.bssid;
            wifi.current_ap.psd = event.value.psd;
            if (wifi.isConnected) {
                wifi.module.disconnect();
            }
            wifi.module.connect({
                ssid: event.value.ssid,
                bssid: event.value.bssid,
                password: event.value.psd
            })
            that.setData({ WifiPrompt: { value: "WiFi — 正在连接\"" + wifi.current_ap.ssid + "\"", refresh: true } });
            that.loadWaitingImg("wifi_list");
        }
    },

    /* 此方法展示窗体后发生 */
    onResume: function (event) {

    },

    /* 当前页状态变化为显示时触发 */
    onShow: function (event) {

    },

    /* 当前页状态变化为隐藏时触发 */
    onHide: function (event) {

    },

    onBtn: function (event) {
        pm.navigateBack();
    },

    /* 此方法关闭窗体前发生 */
    onExit: function (event) {
        clearInterval(this.dateTimer);//app.js中定时器--刷新网络信号
    },
};

Page(page);

page = 0;
